package com.woniuxy.qimengorder.controller;

import com.woniuxy.qimengcommons.bean.ReturnMsg;
import com.woniuxy.qimengcommons.enums.RespStatus;
import com.woniuxy.qimengorder.bean.OrderBean;
import com.woniuxy.qimengorder.service.OrderService;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (OrderBean)表控制层
 *
 * @author makejava
 * @since 2020-08-25 20:10:26
 */
@RestController
@RequestMapping("/order")
public class OrderController {
    /**
     * 服务对象
     */
    @Resource
    private OrderService orderService;

    /**
     * 家长购买课程后生成订单
     * @param orderBean
     * @return
     */
    @PostMapping(value = "/more", produces = MediaType.APPLICATION_JSON_VALUE)
    public ReturnMsg save(OrderBean orderBean) {
        ReturnMsg returnMsg = new ReturnMsg(RespStatus.SUCCESS);

        try {
            orderService.insert(orderBean);
        } catch (Exception e) {
            e.printStackTrace();
            returnMsg=new ReturnMsg(RespStatus.FAILED);
        }
        return returnMsg;
    }

    /**
     * 通过订单编号查询单条数据
     * @param no 订单编号
     * @return 单条数据
     */
    @GetMapping(value = "/selectOne/{no}",produces = MediaType.APPLICATION_JSON_VALUE)
    public ReturnMsg selectOne(@PathVariable("no") String no) {
        ReturnMsg returnMsg = new ReturnMsg(RespStatus.SUCCESS);

        try {
            OrderBean orderBean = orderService.queryById(no);
            returnMsg.setData(orderBean);
        }catch (Exception e){
            e.printStackTrace();
            returnMsg=new ReturnMsg(RespStatus.FAILED);
        }

        return returnMsg;
    }

}